#include "util.h"

int util_snprintf(char *buf , int buflen , const char *format , ...)
{
    int r;
    va_list ap;
    va_start(ap , format);
    r = util_vsnprintf(buf , buflen , format , ap );
    va_end(ap);
    return r;
}

int util_vsnprintf(char *buf , int buflen , const char *format ,va_list ap)
{
#ifdef _MSC_VER
    int r = _vsnprintf(buf,buflen,format,ap);
    buf[buflen-1]='0';
    if (r >= 0)
        return r;
    else
        return _vscprintf( format , ap );
#else
    int r = vsnprintf(buf,buflen,format,ap);
    buf[buflen-1]='0';
    return r;
#endif
}


